{% extends 'base.html' %}
{% block title %}
步骤编辑
{% endblock %}
{% block content %}
{% if apitest %}
<h4>步骤——{{ apitest.name }}</h4>
{% endif %}
<div class="row">
    <div class="col-2"></div>
    <div class="col-8">
        <form method="post" class="needs-validation" novalidate>
            <div class="row">
                <div class="col-md-6 mb-3">
                    <label for="name">步骤名称<label style="color: red;">*</label></label>
                    <input type="text" class="form-control" id="name" name="name" value="{{ apistep.name }}"
                        placeholder="请输入步骤名称..." required>
                    <div class="invalid-feedback">
                        Valid first name is required.
                    </div>
                </div>
                <div class="col-md-6 mb-3">
                    <label for="method">请求方法<label style="color: red;">*</label></label>
                    <select class="form-control" id="method" defaultValue="{{ apistep.method }}" name="method">
                        {% for method in methods %}
                        <option {% if apistep.method==method[0] %} selected="selected" {% endif %}>{{ method[0] }}
                        </option>
                        {% endfor %}
                    </select>
                </div>
            </div>
            <div class="mb-3">
                <label for="url">请求地址<label style="color: red;">*</label></label>
                <div class="radio">
                    {% if apiurl %}
                    {% for url in apiurl %}
                    <label class="radio-inline">
                        <input type="radio" name="url" value="{{ url.id }}" {% if apistep.apiurl_id==url.id %} checked
                            {% endif %}>{{url.name }}
                    </label>
                    {% endfor %}
                    {% else %}
                    <p style="color: red;">请先新建一个测试地址</p>
                    {% endif %}

                </div>
            </div>
            <div class="mb-3">
                <label for="route">请求路径<label style="color: red;">*</label></label>
                <div class="input-group">
                    <div class="input-group-prepend">
                        <span class="input-group-text">/</span>
                    </div>
                    <input type="text" {% if apistep.route %} value="{{ apistep.route }}" {% endif %}
                        class="form-control" id="route" name="route" placeholder="请输入请求路径..." required>
                    <div class="invalid-feedback" style="width: 100%;">
                        Your username is required.
                    </div>
                </div>
            </div>
            <div class="mb-3">
                <label for="headers">请求头</label>
                <textarea class="form-control" id="headers1" name="headers"
                    placeholder="直接在浏览器中复制请求头然后粘贴至此即可">{{ apistep.headers }}</textarea>
            </div>
            <div class="mb-3">
                <label for="request_data">请求内容</label>
                <textarea class="form-control" id="request_data1" name="request_data"
                    placeholder='{"json":{"username":"admin","password":"admin"}}'>{{ apistep.request_data }}</textarea>
                <p>输入json格式的字符串，键名称必须符合requests库的相应参数规范; 示例：</p>
                <a href="https://requests.readthedocs.io/zh_CN/latest/user/quickstart.html#url">requests官方文档</a>
            </div>
            
            <div class="mb-3">
                <label for="expected_result">预期结果<label style="color: red;">*</label></label>
                <input type="text" class="form-control" id="expected_result" value="{{ apistep.expected_result }}"
                    name="expected_result" required>
            </div>
            <div class="mb-3">
                <label for="expected_regular">预期正则</label>
                <input type="text" class="form-control" id="expected_regular" value="{{ apistep.expected_regular }}"
                    name="expected_regular">
            </div>
            <div class="mb-3">
                <label for="request_extract">
                    <font style="color:brown;">提取Request变量{请求值}</font>
                </label>
                <input type="text" class="form-control" id="request_extract" value="{{ apistep.request_extract }}" name="request_extract">
            </div>
            <div class="mb-3">
                <label for="response_extract">
                    <font style="color:crimson;">提取Response变量{响应值}</font>
                </label>
                <input type="text" class="form-control" id="response_extract" value="{{ apistep.response_extract }}" name="response_extract">
            </div>
            <div class="form-group">
                <label for="url">是否删除</label></label>
                <div class="radio">
                    <label><input type="radio" name="delete">删除勾选框(<font style="color: red;">请谨慎操作</font>)</label>
                </div>
            </div>
            <hr class="mb-4">
            <div class="form-actions well well-sm clearfix">
                <button type="submit" class="default btn btn-primary hide-xs">
                    <i class="fa fa-save"></i>
                    更新
                </button>
            </div>
        </form>
    </div>
</div>
{% endblock %}